home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / PathBrowser.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  128 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. import sys
  6. import imp
  7. from TreeWidget import TreeItem
  8. from ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
  9.  
  10. class PathBrowser(ClassBrowser):
  11.     
  12.     def __init__(self, flist):
  13.         self.init(flist)
  14.  
  15.     
  16.     def settitle(self):
  17.         self.top.wm_title('Path Browser')
  18.         self.top.wm_iconname('Path Browser')
  19.  
  20.     
  21.     def rootnode(self):
  22.         return PathBrowserTreeItem()
  23.  
  24.  
  25.  
  26. class PathBrowserTreeItem(TreeItem):
  27.     
  28.     def GetText(self):
  29.         return 'sys.path'
  30.  
  31.     
  32.     def GetSubList(self):
  33.         sublist = []
  34.         for dir in sys.path:
  35.             item = DirBrowserTreeItem(dir)
  36.             sublist.append(item)
  37.         
  38.         return sublist
  39.  
  40.  
  41.  
  42. class DirBrowserTreeItem(TreeItem):
  43.     
  44.     def __init__(self, dir, packages = []):
  45.         self.dir = dir
  46.         self.packages = packages
  47.  
  48.     
  49.     def GetText(self):
  50.         if not self.packages:
  51.             return self.dir
  52.         else:
  53.             return self.packages[-1] + ': package'
  54.  
  55.     
  56.     def GetSubList(self):
  57.         
  58.         try:
  59.             if not self.dir:
  60.                 pass
  61.             names = os.listdir(os.curdir)
  62.         except os.error:
  63.             return []
  64.  
  65.         packages = []
  66.         for name in names:
  67.             file = os.path.join(self.dir, name)
  68.             if self.ispackagedir(file):
  69.                 nn = os.path.normcase(name)
  70.                 packages.append((nn, name, file))
  71.                 continue
  72.         
  73.         packages.sort()
  74.         sublist = []
  75.         for nn, name, file in packages:
  76.             item = DirBrowserTreeItem(file, self.packages + [
  77.                 name])
  78.             sublist.append(item)
  79.         
  80.         for nn, name in self.listmodules(names):
  81.             item = ModuleBrowserTreeItem(os.path.join(self.dir, name))
  82.             sublist.append(item)
  83.         
  84.         return sublist
  85.  
  86.     
  87.     def ispackagedir(self, file):
  88.         if not os.path.isdir(file):
  89.             return 0
  90.         
  91.         init = os.path.join(file, '__init__.py')
  92.         return os.path.exists(init)
  93.  
  94.     
  95.     def listmodules(self, allnames):
  96.         modules = { }
  97.         suffixes = imp.get_suffixes()
  98.         sorted = []
  99.         for suff, mode, flag in suffixes:
  100.             i = -len(suff)
  101.             for name in allnames[:]:
  102.                 normed_name = os.path.normcase(name)
  103.                 if normed_name[i:] == suff:
  104.                     mod_name = name[:i]
  105.                     if not modules.has_key(mod_name):
  106.                         modules[mod_name] = None
  107.                         sorted.append((normed_name, name))
  108.                         allnames.remove(name)
  109.                     
  110.                 modules.has_key(mod_name)
  111.             
  112.         
  113.         sorted.sort()
  114.         return sorted
  115.  
  116.  
  117.  
  118. def main():
  119.     import PyShell as PyShell
  120.     PathBrowser(PyShell.flist)
  121.     if sys.stdin is sys.__stdin__:
  122.         mainloop()
  123.     
  124.  
  125. if __name__ == '__main__':
  126.     main()
  127.  
  128.